<template>
  <!-- 增值服务字段添加 -->
  <el-dialog title="添加收费项目" :visible.sync="openIcreServiceFeeFieldAdd" width="400px" append-to-body :destroy-on-close="true" :before-close="beforeClose">
    <el-form ref="formParams" :model="formParams" :rules="rules" label-width="120px" :inline="true">
      <el-form-item label="收费项目" prop="name">
        <el-input
        v-model="formParams.name"
        placeholder="请输入收费金额"
        clearable
        />
      </el-form-item>
      <el-form-item label="备注:" prop="itbz">
        <el-input
        v-model="formParams.itbz"
        placeholder="请输入备注"
        clearable
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleAdd">添加</el-button>
      </div>
  </el-dialog>
</template>

<script>
import { addChargeItems } from "@/api/storage/commonGoods/increServiceFee";

export default {
  name: "increServiceFeeFieldAdd",
  data() {
    return {
       // 表单校验
      rules: {
        name: [
          { required: true, message: "收费项目不能为空", trigger: "blur" }
        ],
      },
      //弹窗状态
      openIcreServiceFeeFieldAdd: false,
      // 添加参数
      formParams: {
        name:"",
        itbz:""
      },
    };
  },
  methods: {
    /**修改 */
    handleAdd() {
      this.$modal.loading("数据正在添加中，请稍等...")
      addChargeItems(this.formParams).then(response => {
        this.$modal.closeLoading()
        this.$modal.msgSuccess('添加成功！')
        this.close()
        this.$emit('refresh', true)
      }).catch(()=> {
        this.$modal.closeLoading()
      })
    },
    /**关闭弹窗 */
    beforeClose(done) {
      this.close()
      done()
    },
    /**关闭窗口 */
    close() {
      this.changeIcreServiceFeeFieldAdd()
      this.reset()
    },
    /**改变窗口状态 */
    changeIcreServiceFeeFieldAdd() {
      this.openIcreServiceFeeFieldAdd = !this.openIcreServiceFeeFieldAdd;
    },
    /** 重置数据 */
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
    /**打开弹窗 */
    open() {
      this.changeIcreServiceFeeFieldAdd()
    },
  }
};
</script>
